import { noticeScrollList } from "@src/api/loan";
import router from "@src/router";
Component({
  options: {
    addGlobalClass: true,
  },
  properties: {
    bizData: {
      type: Object,
      value: {},
    },
    user: {
      type: Boolean,
      value: false,
    },
    login: {
      type: Boolean,
      observer: function (newVal, oldVal) {
        this.getData();
      },
    },
  },
  lifetimes: {
    ready() {
      let { params } = this.data.bizData;
      this.setData({
        bizDataParams: JSON.parse(params),
        fileBaseUrl: getApp().globalData.extConfig.fileBaseUrl,
      });
      this.getData();
    },
    detached() {
      clearInterval(this.data.inter);
    },
  },
  pageLifetimes: {
    hide() {
      clearInterval(this.data.inter);
    },
    show(){
      this.getData()
    }
  },
  data: {
    bizDataParams: "",
    defaultIcon: "/img/canyin/affiche_bg.png",
    scrollTop: 0,
    fileBaseUrl: "",
    activeIndex: 0,
    afficheList: [],
    inter: "",
  },
  methods: {
    changeScroll() {
      if (this.data.afficheList.length <= 1) {
        return;
      }
      this.data.inter && clearInterval(this.data.inter);
      this.data.inter = setInterval(() => {
        let { activeIndex, afficheList } = this.data;
        if (activeIndex === afficheList.length - 1) {
          this.setData({ activeIndex: 0 });
        } else {
          this.setData({ activeIndex: activeIndex + 1 });
        }
      }, 3000);
    },
    getData() {
      noticeScrollList({}).then((res) => {
        if (res.code === 0) {
          // this.setData({
          //   afficheList: [
          //     "新商家入驻了入驻了入新商家入驻了入驻了入新商家入驻了入驻了入",
          //     "新商家入驻了入驻了",
          //   ],
          // });
          this.setData({ afficheList: res.data });
          this.changeScroll();
        }
      });
    },
    toList() {
      if (!this.data.login) {
        this.triggerEvent("login");
        return;
      }
      router.push({
        name: "loanmove/afficheList",
      });
    },
  },
});
